Skip to main content

Questions tagged [cast]

Converts an expression of one data type to another.

0 votes
1 answer
119 views

What is the idiomatic way to truncate a string down to 100 byte-pairs?

nvarchar(100) holds 100 byte-pairs, as documented here. LEFT([Your String], 100) truncates your string down to 100 characters as documented here. These are not the same. Foolishly, I have used LEFT([...
J. Mini's user avatar
  • 545
4 votes
1 answer
294 views

Postgres strange conversion of the string 'now' to timestamp

It looks like postgres treats the string 'now()' the same as a call to the now() function. Why does postgres allow this? select 'now'::timestamp; or this? select 'now()'::timestamp; or even this? ...
Christian Long's user avatar
1 vote
1 answer
818 views

PostgreSQL 15: ERROR: operator is not unique: unknown || double precision

we are using a PostgreSQL version 15 and have added 13 conversions from this blog entry: http://petereisentraut.blogspot.com/2008/03/readding-implicit-casts-in-postgresql.html However, only now we ...
Athris's user avatar
  • 21
1 vote
1 answer
23 views

How can I sort by "release" in Mysql, where e.g. 10.10 comes after 10.9, with non-numerical entries both before and after?

If I have a table as per https://www.db-fiddle.com/f/arPEdUty3U6AJEQfqYEyRc/1 with a list of releases: INSERT INTO `releases` (`ReleaseID`, `ReleaseNumber`) VALUES (1, '10.6'), (2, '10.8'), (3, '_TBD')...
Ben Holness's user avatar
2 votes
2 answers
2k views

XML datatype instance has too many levels of nested nodes. Maximum allowed depth is 128 levels

This is the error message I get when running the query below: Msg 6335, Level 16, State 102, Line 43 XML datatype instance has too many levels of nested nodes. Maximum allowed depth is 128 levels. ...
Marcello Miorelli's user avatar
0 votes
0 answers
18 views

Combine INT, TIME fields and compute Elapsed Percentage

Need calculation and conversion help... Columns: [Days] INT [hh:mm:ss] Time [AllowedRuntimeMinutes] INT Need to combine [Days]+[hh:mm:ss] as the duration the query has been running, and then calculate ...
CrushingIT's user avatar
3 votes
1 answer
889 views

In Snowflake, how do I CAST CURRENT_TIMESTAMP up to the minute only?

In Snowflake, how do I CAST CURRENT_TIMESTAMP up to the minute only. I don't want seconds, milliseconds, or timezone included in my result.
Jimbo's user avatar
  • 65
1 vote
0 answers
803 views

Convert Integer Array to JSON Array

I'm not sure how I should go about converting int[] to json[], here's what I've tried so far: db=# alter table product alter column images type json[] using images::json[]; ERROR: cannot cast type ...
Shayan's user avatar
  • 111
2 votes
1 answer
1k views

How can I utilize an index with a different type or collation in a LEFT JOIN in MySQL?

I am trying to debug a slow query, and when I EXPLAIN the SQL, I get a warning: Warning: #1739 Cannot use ref access on index '[index name]' due to type or collation conversion on field '[field name]' ...
Ben Holness's user avatar
0 votes
2 answers
3k views

Convert hex string representation to hex number in SQL Server T-SQL

I have been given a dataset where hexadecimal numbers have been stored as a quasi-hex string representation intended to be human-friendly, e.g. "16A1". Is there a conversion function in T-...
Tim's user avatar
  • 545
0 votes
1 answer
135 views

Why isn't it trivial to create a virtual integer timestamp column from a TIMESTAMP column in MySQL?

There's no way to extract an integer timestamp from a TIMESTAMP column in a virtual column context in MySQL because UNIX_TIMESTAMP is not allowed in virtual columns. Why isn't this a trivial task?
Dan's user avatar
  • 235
0 votes
2 answers
258 views

Can I create a cast from a composite (table or row) type to a domain?

Let's say I have a simple table foo, and domain bar CREATE TABLE foo(x) AS VALUES (1),(2),(3); CREATE DOMAIN bar AS text; Is it possible to make a cast such that I can do SELECT foo::bar FROM foo; ...
Evan Carroll's user avatar
  • 63.9k
2 votes
1 answer
406 views

How to copy data between postgres schemas if there are objects?

I removed shop from database, that should not be removed. Fortunately I had backup and reverted this backup to schema public_backup. Now I am trying to restore only this shop. I can't override my ...
Daniel's user avatar
  • 209
1 vote
1 answer
525 views

Best way to cast a VIEW row type to the underlying TABLE row type

I have a table with an index and a row-level security policy. Due to this problem (more details: 1, 2, 3, 4, 5), the index is not used when the policy applies, which makes my queries unbearably slow. ...
Bergi's user avatar
  • 514
3 votes
1 answer
644 views

I can't understand a syntax error issue in SQL / TimeScaleDB

This does NOT compile: SELECT add_compression_policy( hypertable => 'exchange.candles', compress_after => INTERVAL ((SELECT now()::DATE::timestamp - (SELECT min(last_ts) FROM exchange....
Thomas's user avatar
  • 303

15 30 50 per page
1
2 3 4 5
9