eastwater
eastwater

Reputation: 5588

SQL cast target types: standardized?

SQL function

cast(expression as type):

It is ANSI standard. Is the type standardized? what types are allowed? Are they different from database to database?

Looked at the MySQL and others. MySQL has signed/unsigned, others has INT.

Upvotes: 1

Views: 569

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269873

CAST() is ANSI standard. Off the top of my head, ANSI data types are things like:

  • DECIMAL/NUMERIC(scale, precision)
  • VARCHAR()/CHAR()
  • DATE/TIME/DATETIME/INTERVAL
  • DOUBLE PRECISION/FLOAT
  • BIGINT/INT/SMALLINT

MySQL changes the syntax a bit. So, UNSIGNED and SIGNED are used instead of INT. And CHAR is used for all the character types. Other databases have their own modification for CAST(). For instance Google BigQuery uses string instead of the character types.

Upvotes: 1

Related Questions